"""
Case Type   : Compatibility
Case Name   : text转date类型测试
Create At   : 2025/5/9
Owner       : wan005
Description :
    1.B库下执行text转date类型测试
Expect      :
    1.成功
History     :
"""
import os
import unittest
from yat.test import Node
from testcase.utils.Common import Common
from testcase.utils.CommonSH import CommonSH
from testcase.utils.Logger import Logger


class Security(unittest.TestCase):
    def setUp(self):
        self.logger = Logger()
        self.logger.info(f'---{os.path.basename(__file__)} start---')
        self.userNode = Node(node='PrimaryDbBmode')
        self.db_name = self.userNode.db_name
        self.common = Common()
        self.sh_primy = CommonSH()

    def test_converse(self):
        text = '---step1:B库下执行text转date类型测试;expect:成功---'
        self.logger.info(text)
        sql_cmd1 = 'set datestyle to Postgres, MDY;' \
                   'select date\'2000-1-1\';'
        res1 = self.sh_primy.execut_db_sql(sql_cmd1, dbname=self.db_name)
        self.logger.info(res1)
        self.common.equal_sql_mdg(res1, 'SET', 'date', '01-01-2000',
                                  '(1 row)', flag=2)

        sql_cmd2 = 'set datestyle to Postgres, MDY;' \
                   'select date\'2000-1-1\'::text;'
        res2 = self.sh_primy.execut_db_sql(sql_cmd2, dbname=self.db_name)
        self.logger.info(res2)
        self.common.equal_sql_mdg(res2, 'SET', 'text', '01-01-2000',
                                  '(1 row)', flag=2)

        sql_cmd3 = 'set datestyle to Postgres, MDY;' \
                   'select date\'2000-1-1\'::text::date;'
        res3 = self.sh_primy.execut_db_sql(sql_cmd3, dbname=self.db_name)
        self.logger.info(res3)
        self.common.equal_sql_mdg(res3, 'SET', 'date', '01-01-2000',
                                  '(1 row)', flag=2)

    def tearDown(self):
        self.logger.info(f'---{os.path.basename(__file__)} start---')
